<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<?php include '../public/header_index.php' ?>
<?php include "../public/header_main.php";?>
<style>
    .laytp-container #table-card{padding: 0!important;}
    #mainnav{padding-bottom: 0!important;}
    .left_but{padding: 10px 0 10px 15px;border-bottom: 1px solid #d1d1d1}
    .layui-card{padding-bottom: 0;margin-bottom: 0}
    .layui-table-tool-temp{padding-right:0 }
    .layui-table tr {
        height: unset !important;
        line-height: unset !important;
    }


    .table-click-color{background: #FFFFFF!important;}
    .layui-table-hover{background: #FFFFFF!important;}


    div[lay-id="datalist"] td:first-child{
        width: 50px !important;
    }
    div[lay-id="datalist"] td[data-field="status"]{
        width: 48px !important;
    }
    div[lay-id="datalist"] td[data-field="enname"]{
        width: 300px !important;
    }
    div[lay-id="datalist"] td[data-field="enfeat"]{
        width: 300px !important;
    }
    div[lay-id="datalist"] td[data-field="enunit"]{
        width: 150px !important;
    }
    div[lay-id="datalist"] td[data-field="enword"]{
        width: 150px !important;
    }
    div[lay-id="datalist"] td[data-field="han"]{
        width: 150px !important;
    }
    div[lay-id="datalist"] .layui-table-body{
        overflow-x: hidden!important;
    }

    div[lay-id="datalist"] td[data-field="enname"] div{
        width: 300px !important;
    }
    div[lay-id="datalist"] td[data-field="enunit"] div{
        width: 150px !important;
    }
    div[lay-id="datalist"] td[data-field="enword"] div{
        width: 150px !important;
    }
    div[lay-id="datalist"] td[data-field="han"] div{
        width: 150px !important;
    }


</style>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title" id="titss"></span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" lay-submit="" lay-filter="add">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    var param_enginid = getQueryVariable('enginid') || 0;
    var param_qingid = getQueryVariable('qingid') || 0;
    var param_index = getQueryVariable('index') || 0;
    var param_type = getQueryVariable('type') || '';


    var param_list = $('.'+param_type, parent.document).eq(param_index).attr('list');
    if(param_list != undefined && param_list != false){
        param_list = JSON.parse(param_list)
    }else{
        param_list = '';
    }


    var pubenfeatWid = 300;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;



        layui.config({
            base: '../../static/component/lib/opTable'
        }).extend({
            opTable: '/opTable'
        }).use(['opTable'],function() {
            var opTable = layui.opTable.render({
                elem: '#datalist'
                ,toolbar: TabInit.toolbar
                ,method:TabInit.method
                ,defaultToolbar: ['filter', '', 'print']
                ,height: 'full-102'
                ,url: server_api_name+ask_main_qingnav_list
                ,page: false
                ,openType: 1
                ,request: {pageName: 'page',limitName: 'pagesize'}
                ,where:{enginid:param_enginid, qingid:param_qingid}
                ,parseData: function(res){

                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.data.total,
                        "data": res.data.data
                    };
                }
                ,response: {statusCode: 2000}
                ,cols: [[
                    {field:'status',title:'#',width:48,templet: function(d){
                            return '<input type="checkbox" class="isxuanall" key="'+d.LAY_INDEX+'" lay-filter="isxuanall" lay-skin="primary">';
                        }}
                    ,{field:'enname',title:'项目名称',width:300}
                    ,{field:'enfeat',title:'项目特征描述',minWidth:300}
                    ,{field:'enunit',title:'计量单位',width:150}
                    ,{field:'enword',title:'工程量',width:150}
                    ,{field:'han',title:'含量',width:150}
                ]]
                ,done: function(res, curr, count){
                    $('div[lay-id="datalist"] .layui-table-header thead>tr>th:nth-child(1)').find('.layui-table-sort').remove();
                    $('div[lay-id="datalist"] .layui-table-header thead>tr>th:nth-child(2)').find('.layui-table-sort').remove();
                    pubenfeatWid = $('div[lay-id="datalist"]').find('.layui-table-header tr th[data-field="enfeat"]').width();

                    $("#opTableZhanAll").click();
                    $(".datalistopTable-i-table-open").parent('div').html('#');
                }
                , openTable: function (itemData) {
                    var elemId = 'child_1_' + itemData.LAY_INDEX;
                    return {
                        elem: '#child_1_' + itemData.LAY_INDEX
                        , id: elemId
                        ,method:'post'
                        ,url: server_api_name+ask_main_qinglist_list
                        ,page: false
                        ,where:{enginid:param_enginid,fenname:itemData.enname,qingid:param_qingid,list:param_list}
                        ,parseData: function(res){
                            return {
                                "code": res.code,
                                "msg": res.message,
                                "count": res.data.total,
                                "data": res.data.data
                            };
                        }
                        ,response: {statusCode: 2000}
                        ,cols: [[
                            {field:'status',title:'#',width:48,templet: function(d){
                                    if(d.LAY_CHECKED){
                                        return '<input type="checkbox" lay-filter="noxuanall" class="isxuan_'+itemData.LAY_INDEX+'" value="'+itemData.LAY_INDEX+'" lay-skin="primary" checked>';
                                    }else{
                                        return '<input type="checkbox" lay-filter="noxuanall" class="isxuan_'+itemData.LAY_INDEX+'" value="'+itemData.LAY_INDEX+'" lay-skin="primary">';
                                    }
                                }}
                            ,{field:'enname',title:'项目名称',width:300}
                            ,{field:'enfeat',title:'项目特征描述',minWidth:300}
                            ,{field:'enunit',title:'计量单位',width:150}
                            ,{field:'enword',title:'工程量',width:150}
                            ,{field:'han',title:'含量',width:150}
                            ,{field:'id',title:'编号',hide:true}
                        ]]
                        ,done: function(res, curr, count){
                            $(".opTable-open-td").find('th').hide();
                            $(".child_1_1opTable-i-table-open").parent('div').click();
                            $(".child_1_1opTable-i-table-open").parent('div').html('#');
                            // $(".opTable-open-td").find('td').css('cssText','background-color: #deeafd !important;');
                            // $(".opTable-open-td").find('td').mouseover(function () {
                            //     $(this).parent().find('td').each(function () {
                            //         $(this).css('cssText','background-color: #e7ecf5 !important;');
                            //     })
                            // });
                            // $(".opTable-open-td").find('td').mouseout(function () {
                            //     $(this).parent().find('td').each(function () {
                            //         $(this).css('cssText','background-color: #deeafd !important;');
                            //     })
                            // });
                            $('td[data-field="enfeat"] div').attr('style',"width:"+(pubenfeatWid)+"px");
                        }
                        , openTable: function (itemData) {
                            var elemId = 'child_2_' + itemData.LAY_INDEX;
                            return {
                                elem: '#child_2_' + itemData.LAY_INDEX
                                , id: 'child_2_' + itemData.LAY_INDEX
                                ,method:'post'
                                ,url: server_api_name+ask_main_qinglist_list
                                ,page: false
                                ,where:{enginid:param_enginid,fenname:itemData.fenname,ziname:itemData.enname,qingid:itemData.qingid,list:param_list}
                                ,parseData: function(res){
                                    return {
                                        "code": res.code,
                                        "msg": res.message,
                                        "count": res.data.total,
                                        "data": res.data.data
                                    };
                                }
                                ,response: {statusCode: 2000}
                                ,cols: [[
                                    {field:'status',title:'#',width:48,templet: function(d){
                                            if(d.LAY_CHECKED){
                                                return '<input type="checkbox" lay-filter="childxuanall" class="childxuanall_'+itemData.LAY_INDEX+'" value="'+itemData.LAY_INDEX+'" lay-skin="primary" checked>';
                                            }else{
                                                return '<input type="checkbox" lay-filter="childxuanall" class="childxuanall_'+itemData.LAY_INDEX+'" value="'+itemData.LAY_INDEX+'" lay-skin="primary">';
                                            }
                                        }}
                                    ,{field:'enname',title:'项目名称',width:300}
                                    ,{field:'enfeat',title:'项目特征描述',minWidth:300}
                                    ,{field:'enunit',title:'计量单位',width:150}
                                    ,{field:'enword',title:'工程量',width:150}
                                    ,{field:'han',title:'含量',width:150}
                                    ,{field:'id',title:'编号',hide:true}
                                ]]
                                ,done: function(res, curr, count){
                                    $(".opTable-open-td").find('th').hide();
                                    $('td[data-field="enfeat"] div').attr('style',"width:"+(pubenfeatWid)+"px");
                                }
                            }
                        }
                    }
                }
            });
        });



        form.on('checkbox(isxuanall)',function (data) {
            var keyss = $(data.elem).attr("key");
            if($(data.elem).prop("checked")){
                // $("input[class^='isxuan_']").prop("checked", true);
                $("input[class^='childxuanall_']").prop("checked", true);
                $(".isxuan_"+keyss).prop("checked", true);
            }else{
                // $("input[class^='isxuan_']").prop("checked", false);
                $("input[class^='childxuanall_']").prop("checked", false);
                $(".isxuan_"+keyss).prop("checked", false);
            }
            render_from();
        });

        form.on('checkbox(noxuanall)',function (data) {
            var value = data.elem.className.split('_')[1];
            var pvalue = $(data.elem).parents('tr').attr('data-index');
            if(pvalue != undefined){
                pvalue = parseInt(pvalue) + 1;
            }else{
                pvalue = '';
            }
            if($(data.elem).prop("checked")){
                // 判断上一级的选中
                var checked = 1;
                $(".isxuan_"+value).each(function () {
                    if($(this).next().attr('class') != 'layui-unselect layui-form-checkbox layui-form-checked'){
                        checked = 0;
                    }
                });
                if(checked == 1){
                    $('.isxuanall').each(function () {
                        if($(this).attr('key') == value){
                            $(this).next().attr('class','layui-unselect layui-form-checkbox layui-form-checked');
                            $(this).prop("checked", true);
                        }
                    });
                }
                // 判断下一级的选中
                if(pvalue != ''){
                    $(".childxuanall_"+pvalue).next().attr('class','layui-unselect layui-form-checkbox layui-form-checked');
                    $(".childxuanall_"+pvalue).prop("checked", true);
                }
            }else{
                // 判断上一级取消
                $('.isxuanall').each(function () {
                    if($(this).attr('key') == value){
                        $(this).next().attr('class','layui-unselect layui-form-checkbox');
                        $(this).prop("checked", false);
                    }
                });
                // 判断下一级的取消
                if(pvalue != ''){
                    $(".childxuanall_"+pvalue).next().attr('class','layui-unselect layui-form-checkbox');
                    $(".childxuanall_"+pvalue).prop("checked", false);
                }
            }
            render_from();
        });

        form.on('checkbox(childxuanall)',function (data) {
            if($(data.elem).prop("checked")){
                var checked = 1;
                $(data.elem).parent().parent().parent().parent().find("input[class^='childxuanall_']").each(function () {
                    if($(this).next().attr('class') != 'layui-unselect layui-form-checkbox layui-form-checked'){
                        checked = 0;
                    }
                });
                if(checked == 1){
                    $(data.elem).parents('tr').parents('tr').prev().find("input[class^='isxuan_']").next().attr('class','layui-unselect layui-form-checkbox layui-form-checked');
                    $(data.elem).parents('tr').parents('tr').prev().find("input[class^='isxuan_']").prop("checked", true);
                }
            }else{
                $(data.elem).parents('tr').parents('tr').prev().find("input[class^='isxuan_']").next().attr('class','layui-unselect layui-form-checkbox');
                $(data.elem).parents('tr').parents('tr').prev().find("input[class^='isxuan_']").prop("checked", false);
            }
            render_from();
        });




        form.on('submit(add)', function(data){
            openPage('analy_xuan_after.php');
        });




        listTableSearch(form, table);
    });



</script>
</body>
</html>
